$(function(){
	var editRow = undefined;
	var datagrid;
	
	var newArr=[
                {field: 'name', title: '参数 ', width: 100},
                {field: 'description', title: '描述 ', width: 100,editor:{type:"validatebox"}},
                {field: 'type', title: '类型选择', width: 100,editor:{type:"validatebox",options: { required: true}}},
                {field: 'value', title: '默认值 ', width: 80,editor:{type:"validatebox",options: { required: true}}}
            ];
	
	datagrid=$("#addDatagrid").datagrid({
		columns: [newArr],
		singleSelect:true,
		onAfterEdit: function (rowIndex, rowData, changes) {
            //endEdit该方法触发此事件
            console.info(rowData);
            editRow = undefined;
        },
        onDblClickRow: function (rowIndex, rowData) {
        //双击开启编辑行
            if (editRow != undefined) {
                datagrid.datagrid("endEdit", editRow);
            }
            if (editRow == undefined) {
                datagrid.datagrid("beginEdit", rowIndex);
                editRow = rowIndex;//给editRow对象赋值，index为当前行的索引
            }
        }
	});
	$("#hsql").change(function(){
		var datagrid=$("#addDatagrid").datagrid();
		var content=$(this).val();
		var re = /:.*?:/g;
		var arr = content.match(re);
		console.log(arr);
		if(arr){
			//清除所有行
			datagrid.datagrid('loadData', { total: 0, rows: [] });//清空下方DateGrid 
			$.each(arr,function(i,v){
				var field=v.replace(":","").replace(":","");
				datagrid.datagrid('insertRow',{
					row:{
					name: field,
					description: '',
					type: '',
					value:''
					}
				});
			
			});
		}
	});
});